<?php
  session_cache_limiter('private,must-revalide');
  if ($_POST["Submit"])
  {
	 $user_name = $_POST["user_name"];
	 $user_password =$_POST['user_password'];
	 $user_email = $_POST["user_email"];  //E-mail
	 $user_realname = $_POST["user_realname"];  //姓名
	 $user_id = $_POST["user_id"];
	
	 //權限
	 $p0 = $_POST["p0"]; 
	 $p6 = $_POST["p6"]; 
	 $p7 = $_POST["p7"]; 
	 $p8 = $_POST["p8"]; 
	 $p9 = $_POST["p9"]; 
	 $p10 = $_POST["p10"]; 
	 $p12 = $_POST["p12"]; 
	 $p13 = $_POST["p13"]; 
	 $p14 = $_POST["p14"]; 
	 if($p0==''&$p6==''&$p7==''&$p8==''&$p9==''&$p10==''&$p12==''&$p13==''&$p14=='')
	 {
		MyNotice("該用戶必須具有一個欄目的權限!");
		exit();
	 }
	 $permission= $p0.','.$p6.','.$p7.','.$p8.','.$p9.','.$p10.','.$p12.','.$p13.','.$p14;
	 if($user_password!='')
	 {
		$user_password = md5($user_password);
		$query = "UPDATE $TBL_USERS SET user_password ='$user_password', user_realname='$user_realname',user_email='$user_email',permission='$permission' WHERE user_id='$user_id'";
	 }else{
		$query = "UPDATE $TBL_USERS SET user_realname='$user_realname',user_email='$user_email',permission='$permission' WHERE user_id='$user_id'";
	 }
	 mysql_query($query,$con) or die("出错了: 1");      
	 MyNotice("管理员修改成功",2, "member.php");    
     exit(0);
  }
	$tpl = new PhplibTpl("templates");
	$tpl -> set_file("main", "edit_member.htm");
	$id = (int)$_GET['USER_ID'];
	$query = "SELECT * FROM $TBL_USERS WHERE user_id='$id'";
	$result = mysql_query($query) or die(mysql_error());
	$rows = mysql_fetch_array($result);
	$user_id = $rows["user_id"];
	$username = $rows["user_name"];  //用户名
	$user_email = $rows["user_email"];  //用户名
	$del_url="?mode=del_member&id=".$rows['user_id'];	
	$user_regdate = $rows["user_regdate"];  //注册日期
	$user_lastvisit = date("Y-m-j H:m:i", $rows["user_lastvisit"]);  //最后登录的时间
	$sin_name = $rows["user_realname"];  //真实姓名

	$per = explode(',',$rows["permission"]);	
	for($i=0;$i<count($per);$i++)
	{
		if($per[$i]==0&$per[$i]!='')
		{
			$p0 ='checked="checked"';
			
		}
		if($per[$i]==6)
		{
			$p6 ='checked="checked"';
			
		}
		if($per[$i]==7)
		{
			$p7 ='checked="checked"';
			
		}
		if($per[$i]==8)
		{
			$p8 ='checked="checked"';
			
		}
		if($per[$i]==9)
		{
			$p9 ='checked="checked"';
			
		}
		if($per[$i]==10)
		{
			$p10 ='checked="checked"';
			
		}
		if($per[$i]==12)
		{
			$p12 ='checked="checked"';
			
		}
		if($per[$i]==13)
		{
			$p13='checked="checked"';
			
		}
		if($per[$i]==14)
		{
			$p14 ='checked="checked"';
			
		}
	}

	$tpl -> set_var(array(
					"USER_ID" => $user_id,
					"USERNAME" => $username,
					"DEL_URL" => $del_url,
					"last_visit" => $user_lastvisit,
					"USER_REGDATE" => $user_regdate,
					"REAL_NAME" => $sin_name,
					"user_email" => $user_email,
					"p0" => $p0,
					"p6" => $p6,
					"p7" => $p7,
					"p8" => $p8,
					"p9" => $p9,
					"p10" =>$p10,
					"p12" => $p12,
					"p13" => $p13,
					"p14" => $p14,
					));  
  $tpl -> set_var( $conf);
  $tpl -> parse("Out_main", "main");
  $tpl -> p("Out_main");
  exit(0);
?> 